/**
 * 定义全局过滤器
 *
 * 时间戳转换日期
 *
 */

let globalFilter = {
  // 时间戳转换日期
  formatDate: (value) => {
    let date = new Date(value)
    let y = date.getFullYear()
    let MM = date.getMonth() + 1
    MM = MM < 10 ? '0' + MM : MM
    let d = date.getDate()
    d = d < 10 ? '0' + d : d
    let h = date.getHours()
    h = h < 10 ? '0' + h : h
    let m = date.getMinutes()
    m = m < 10 ? '0' + m : m
    let s = date.getSeconds()
    s = s < 10 ? '0' + s : s
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
  },

  /**
   *
   * 获取最新的组件数据
   * @param {*} itemData
   * @param {*} itemKey
   * @returns
   */
  getCommodityItemData(itemData, itemKey) {
    let shopCommodity = JSON.parse(localStorage.getItem('shopCommodity'))
    if (
      shopCommodity[itemData.type] && shopCommodity[itemData.type][itemData.id]
    ) {
      return shopCommodity[itemData.type][itemData.id][itemKey]
    } else {
      return null
    }
  },
}

export default globalFilter
